package com.wechar_rpa.config;

import com.wechar_rpa.model.SubscriptionPlan;
import com.wechar_rpa.repository.SubscriptionPlanRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class DataInitializer implements CommandLineRunner {

    private final SubscriptionPlanRepository planRepository;

    public DataInitializer(SubscriptionPlanRepository planRepository) {
        this.planRepository = planRepository;
    }

    @Override
    public void run(String... args) {
        if (planRepository.count() == 0) {
            // Level 1
            SubscriptionPlan plan1 = new SubscriptionPlan();
            plan1.setLevel(1);
            plan1.setName("基础版");
            plan1.setWhitelistLimit(3);
            plan1.setMonthlyPrice(0.0);
            plan1.setYearlyPrice(0.0);
            planRepository.save(plan1);

            // Level 2
            SubscriptionPlan plan2 = new SubscriptionPlan();
            plan2.setLevel(2);
            plan2.setName("标准版");
            plan2.setWhitelistLimit(20);
            plan2.setMonthlyPrice(100.0);
            plan2.setYearlyPrice(1000.0);
            planRepository.save(plan2);

            // Level 3
            SubscriptionPlan plan3 = new SubscriptionPlan();
            plan3.setLevel(3);
            plan3.setName("高级版");
            plan3.setWhitelistLimit(100);
            plan3.setMonthlyPrice(300.0);
            plan3.setYearlyPrice(3000.0);
            planRepository.save(plan3);

            System.out.println("默认会员等级已初始化。");
        }
    }
}